/**
 * @projectName: petJoyHome
 * @author: 小飞
 * @description: TODO
 * @date: 2024/3/1 15:40
 * @version: 1.0
 */
package com.home.config.securityConfig;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 解决跨域问题
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //设置跨域访问的路径
        registry.addMapping("*/")
                //设置允许跨域请求的域名
                .allowedOriginPatterns("*")
                //是否允许cookie
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                //设置允许的header
                .allowedHeaders("*")
                //跨域允许时间
                .maxAge(3600);
    }
}
